package com.ruoyi.cust.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cust.domain.CityShare;
import com.ruoyi.cust.service.ICityShareService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分享项目Controller
 *
 * @author cjq
 * @date 2024-12-06
 */
@Api("分享项目")
@RestController
@RequestMapping("/city/share")
public class CityShareController extends BaseController {
    @Autowired
    private ICityShareService cityShareService;

    /**
     * 查询分享项目列表
     */
    @ApiOperation("查询分享项目列表")
    @PreAuthorize("@ss.hasPermi('city:share:list')")
    @GetMapping("/list")
    public TableDataInfo list(CityShare cityShare) {
        startPage();
        List<CityShare> list = cityShareService.selectCityShareList(cityShare); return getDataTable(list);
    }

    /**
     * 导出分享项目列表
     */
    @ApiOperation("导出分享项目列表")
    @PreAuthorize("@ss.hasPermi('city:share:export')")
    @Log(title = "分享项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CityShare cityShare) {
        List<CityShare> list = cityShareService.selectCityShareList(cityShare); ExcelUtil<CityShare> util = new ExcelUtil<CityShare>(CityShare. class);
        util.exportExcel(response, list, "分享项目数据");
    }

    /**
     * 获取分享项目详细信息
     */
    @ApiOperation("获取分享项目详细信息")
    @PreAuthorize("@ss.hasPermi('city:share:query')")
    @GetMapping(value = "/{shareId}")
    public AjaxResult getInfo(@PathVariable("shareId") Long shareId) {
        return success(cityShareService.selectCityShareByShareId(shareId));
    }

    /**
     * 新增分享项目
     */
    @ApiOperation("新增分享项目")
    @PreAuthorize("@ss.hasPermi('city:share:add')")
    @Log(title = "分享项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CityShare cityShare) {
        return toAjax(cityShareService.insertCityShare(cityShare));
    }

    /**
     * 修改分享项目
     */
    @ApiOperation("修改分享项目")
    @PreAuthorize("@ss.hasPermi('city:share:edit')")
    @Log(title = "分享项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CityShare cityShare) {
        return toAjax(cityShareService.updateCityShare(cityShare));
    }

    /**
     * 删除分享项目
     */
    @ApiOperation("删除分享项目")
    @PreAuthorize("@ss.hasPermi('city:share:remove')")
    @Log(title = "分享项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{shareIds}")
    public AjaxResult remove(@PathVariable Long[] shareIds) {
        return toAjax(cityShareService.deleteCityShareByShareIds(shareIds));
    }
}
